﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace Wangzeran.CodeMaker.Core.Files
{
    /// <summary>
    /// 输出文件支持
    /// </summary>
    public abstract class FileSupport : IFile
    {

        #region IFile 成员

        /// <summary>
        /// 该类型文件的描述
        /// </summary>
        public abstract string FileDescription
        {
            get;
        }
        /// <summary>
        /// 输出文件的扩展名
        /// </summary>
        public abstract string FileExt
        {
            get;
        }
        /// <summary>
        /// 文件编码类型
        /// </summary>
        public abstract Encoding Encode
        {
            get;
        }

        /// <summary>
        /// 输出文件
        /// </summary>
        /// <param name="content">文件内容</param>
        /// <param name="path">文件路径</param>
        /// <param name="fileName">输出的文件名</param>
        public virtual void OutputFile(string content, string path, string fileName)
        {
            try
            {
                string fullPath = path + "\\" + fileName + "." + FileExt;
                // 写入文件
                using (TextWriter writer = new StreamWriter(fullPath, false, Encode))
                {
                    writer.Write(content);
                    writer.Flush();
                    writer.Close();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        #endregion

    }
}
